import PropTypes from '../_util/vue-types';
import warning from '../_util/warning';

export default {
  name: 'CDetailTitle',
  props: {
    itemDetail: PropTypes.object,
    customSlots: PropTypes.object,
  },
  data() {
    return {};
  },
  render(h) {
    let fn = null;
    let { customSlots } = this;
    let { titleSlot, title, titleSuffix } = this.itemDetail;

    warning(
      !titleSlot || customSlots[titleSlot],
      `titleSlot ${titleSlot} has declared but never used`,
    );

    warning(
      !titleSuffix || customSlots[titleSuffix],
      `titleSuffix ${titleSuffix} has declared but never used`,
    );

    let defaultTitle = (
      <div class="header-title-label">
        {title}
        {titleSuffix && (fn = customSlots[titleSuffix]) && fn()}
      </div>
    );

    return titleSlot && (fn = customSlots[titleSlot]) ? fn({ title }) : title ? defaultTitle : null;
  },
};
